import { analyze } from '/lib/analyze.js';
import axios from 'axios';

export default {
    props: [
        'censorType',
        'isSubmitDisabled',
        'censorStatus',
        'isOperating',
        'fileList',
        'zipFileHash',
    ],
    methods: {
        analyze() {
            analyze.call(this);
        },
        async cleanCache() {
            if (!confirm('确定要清除缓存吗？')) {
                return;
            }
            const uuid = localStorage.getItem('uuid');
            const res = await axios.post('/clean-cache', { uuid });
            if (!res) {
                alert('清除缓存失败，请求无返回');
                return;
            }
            const data = res.data;
            if (!data) {
                alert('清除缓存失败，返回数据为空');
                return;
            }
            if (data.code == 200) {
                alert('清除成功');
            } else {
                alert('清除失败: ' + res.message);
            }
        },
    },
    /* html */
    template: `
    <fieldset>
        <legend>操作</legend>
        <div class="button-wrap">
            <button type="button" id="submit-button" @click="analyze" :disabled=isSubmitDisabled>开始分析</button>
            <button type="button" id="submit-button" @click="cleanCache">清除缓存</button>
            <div v-if="isOperating">系统正在执行中，请勿操作...</div>
        </div>
    </fieldset>
    `,
};
